
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

import '../code.dart';
import '../code.dart';
import '../result_data.dart';
import '../result_data.dart';

///这里执行返回结果的拦截
///将返回结果处理成为app的统一格式
class InterceptorResponse extends InterceptorsWrapper {

  @override
  onResponse(Response response) async {
    RequestOptions options = response.request;
    if (response.data is ResultData)
      return response.data;
    var resultData;
    try {
      if (response.statusCode >= 200 && response.statusCode < 300) {
        resultData = new ResultData(Code.SUCCESS, response.data);
      }
    }catch(e) {
      debugPrint(e.toString() + options.path);
      resultData = ResultData(Code.FAILURE, "");
    }

    return resultData;
  }
}